using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EntLibEC.Cmn;
using EntLibEC.Info.Basic;
using EntLibEC.Info.Sale;
using EntLibEC.Biz;
using EntLibEC.Biz.Sale;

namespace EntLibEC.View.Sale
{
	/// <summary>
	/// Summary description for SOOutStockCheck.
	/// </summary>
	public partial class SOOutStockCheck : PageBase
	{
		protected int sysNo;
		protected string bodyOnLoad = @"javascript:window.open('InvoicePrint.aspx?sysNo=@sysNo');window.opener.__doPostBack('btnQuery','btnQuery');window.close();";

		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if(Request.QueryString["SysNo"]!=null&&Util.IsNaturalNumber(Request.QueryString["SysNo"]))
				sysNo = int.Parse(Request.QueryString["SysNo"]);			
			try
			{
				base.CheckAccess((int)AppEnum.Privilege.SOOutStock,true,null);
				SOInfo soInfo = SOManager.GetInstance().LoadSO(sysNo);
				soInfo.OutTime = DateTime.Now;
				soInfo.OutUserSysNo = this.sInfo.User.SysNo;
				SOManager.GetInstance().OutStock(soInfo);

                bodyOnLoad = bodyOnLoad.Replace("@sysNo", sysNo.ToString());

				LogManager.GetInstance().Write(new LogInfo(soInfo.SysNo,(int)AppEnum.LogType.Sale_SO_OutStock,this.sInfo));
				try
				{
					SOManager.GetInstance().SendEmail(soInfo,(int)AppEnum.SOEmailType.OutStock);
					//SOManager.GetInstance().SendSMS(soInfo);
				}
				catch(Exception ex)
				{
					ErrorLog.GetInstance().Write(ex.Message);
				}
			}
			catch
			{
				bodyOnLoad = "refreshOpener2()";
				return;
			}			
		}
	
	}
}
